{
  LW Objimp -- LightWave Object Importers

  When LightWave encounters a foreign object file which it cannot parse,
  it will call an "ObjectLoader" class server to import it.  All the
  loaders defined for the host will be activated in sequence, and the
  first one to recognize the file will load it.

  Based on lwobjimp.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}

unit LW_Objimp;

{$mode objfpc}{$H+}

interface

uses
  LW_Types   ,
  LW_Meshes  ,
  LW_Monitor ;

const
  LWOBJECTIMPORT_CLASS	 = 'ObjectLoader' ;
  LWOBJECTIMPORT_VERSION = 3 ;

  { The server must set the 'result' field to one of these following values
    before it returns.

    OK		indicates successful parsing of the object file.

    BADFILE	indicates that the loader could not open the file.

    NOREC	indicates that the loader could open the file but could
  		  not recognize the format.

    ABORTED	indicates the that the user manually aborted the load.

    Any other failure is indicated by the generic FAILED value.  In this case,
    the loader may also place a human-readable error message into the buffer
    pointed to by `failedBuf,' provided that `failedLen' is non-zero.         }

  LWOBJIM_OK	   =  0 ;
  LWOBJIM_NOREC	   =  1 ;
  LWOBJIM_BADFILE  =  2 ;
  LWOBJIM_ABORTED  =  3 ;
  LWOBJIM_FAILED   = 99 ;

type
  { The activation function of the server is passed an LWObjectImport
    structure as its local data which includes the filename of the object
    to load.  The loader attempts to parse the input file and calls the
    embedded callbacks to insert the data into LightWave.  It indicates
    its success or failure by setting the 'result' field, and the optional
    failedBuf.

      result	set by the server to one of the LWOBJIM values below.

      filename	the filename of the object to load.

      monitor	progress monitor that can be used to track the import
		      process.

      failedBuf	string buffer for the server to store a human-readable
		      error message if the result code is LWOBJIM_FAILED.

      data		private data pointer to be passed to all the embedded
		      function callbacks.

      done		called when object import is complete.

      layer	start a new layer in the import data.  The layer is
		      defined by an index number and a name string.

      pivot	set the pivot point for the current layer.

      parent	set the index of the parent layer for the current layer.

      lFlags	set the flag bits for the current layer.  The low-order bit
		      is set if this is a hidden layer.

      point	add a new point to the current layer.  The point is given
		      by an XYZ position and the function returns a void pointer
		      as point identifier.

      vmap	select a VMAP for assigning data to points, creating a new
		      VMAP if it does not yet exist.  The VMAP is defined by a
		      type, dimension and name.

      vmapVal	set a vector for a point into the currently selected VMAP.
		      The vector should have the same dimension as the VMAP.

      vmapPDV	set a vector for a point with reference to a specific polygon.
		      This is the "polygon discontinuous value" for the point.

      polygon	add a new polygon to the current layer.  The polygon is
		      defined by a type code, type-specific flags and a list of
		      point identifiers.

      polTag	associate a tag string to the given polygon.  The tag
		      string has a type, the most common being 'SURF'.

      surface	add a new surface to this object.  The surface is defined by
		      the base name, the reference name, and a block of raw
                      surface data.                                            }
  PLWObjectImport = ^TLWObjectImport;
  TLWObjectImport = record
    Result        : Integer          ;
    Filename      : PChar            ; // const
    Monitor       : PLWMonitor       ;
    FailedBuf     : PChar            ;
    FailedLen     : Integer          ;
    Data          : Pointer          ;

    Done        : procedure
                  (       Data     : Pointer    ) ;
    Layer       : procedure
                  (       Data     : Pointer    ;
                          LayerNum : Integer    ;
                          Name     : PChar      ) ;
    Pivot       : procedure
                  (       Data     : Pointer    ;
                          Pivot    : TLWFVector ) ;
    Parent      : procedure
                  (       Data     : Pointer    ;
                          LayerNum : Integer    ) ;
    LayerFlags  : procedure
                  (       Data     : Pointer    ;
                          Flags    : Integer    ) ;
    Point       : function
                  (       Data     : Pointer    ;
                          XYZ      : TLWFVector ) : PLWPnt ;
    Vmap        : procedure
                  (       Data     : Pointer    ;
                          Type_    : PLWID      ;
                          Dim      : Integer    ;
                          Name     : PChar      ) ;
    VmapVal     : procedure
                  (       Data     : Pointer    ;
                          PointID  : PLWPnt     ;
                          Val      : PSingle    ) ;
    Polygon     : function
                  (       Data     : Pointer    ;
                          Type_    : PLWID      ;
                          Flags    : Integer    ;
                          NumPts   : Integer    ;
                          PointID  : PPLWPnt    ) : PLWPol ;
    PolTag      : procedure
                  (       Data     : Pointer    ;
                          PolygonID : PLWPol    ;
                          Type_    : PLWID      ;
                          Tag      : PChar      ) ;
    Surface     : procedure
                  (       Data     : Pointer    ;
                          BaseName : PChar      ;
                          RefName  : PChar      ;
                          ChunkSize : Integer   ;
                          SurfChunk : Pointer   ) ;
    VmapPDV     : procedure
                  (       Data     : Pointer    ;
                          PointID  : PLWPnt     ;
                          PolygonID : PLWPol    ;
                          Val      : PSingle    ) ;
    Vmapsubp    : procedure
                  (       Data     : Pointer    ;
                          Subpint  : UInt32     ) ;
    Vmapskco    : procedure
                  (       Data     : Pointer    ;
                          Sketchcolor : UInt32  ) ;
    CurVmap     : function
                  (       Data     : Pointer    ) : Pointer ;
    LoadBitmap  : function
                  (       Path     : PChar      ) : PLWImage ;
    SwitchLayer : function
                  (       Data     : Pointer    ;
                          LayerNum : Integer    ) : Integer ;
  end;

implementation

end.

